//
// Created by hay boy on 2022/7/19.
//

#ifndef ALGORITHMS_BOOSTER_H
#define ALGORITHMS_BOOSTER_H

#include <iostream>
#include "../../tree/binaryTree/binaryTreeNode.h"

using namespace std;
struct booster{
    int degradeToLeaf,degradeFromParents;
    bool boosterHere;
    void output(ostream& out) const{
        out<<boosterHere<<' '<<degradeToLeaf<<' '<<degradeFromParents<<' ';
    }
    friend ostream& operator<<(ostream& out,booster x){
        x.output(out);
        return out;
    }
};
int tolerance = 3;
void placeBooster(binaryTreeNode<booster> *x){
    x->element.degradeToLeaf = 0;
    binaryTreeNode<booster> *y = x->leftChild;
    if(y!= nullptr){
        int degradation = y->element.degradeToLeaf+y->element.degradeFromParents;
        if(degradation>tolerance){
            x->element.boosterHere = true;
            x->element.degradeToLeaf = y->element.degradeFromParents;
        }else{
            x->element.degradeToLeaf = degradation;
        }
    }
    y = x->rightChild;
    if(y!= nullptr){
        int degradation = y->element.degradeToLeaf+y->element.degradeFromParents;
        if(degradation>tolerance){
            y->element.boosterHere = true;
            degradation = y->element.degradeFromParents;
        }
        if(x->element.degradeToLeaf<degradation){
            x->element.degradeToLeaf = degradation;
        }
    }


}
#endif //ALGORITHMS_BOOSTER_H
